package com.example.controller;

import com.example.data.leave.Leave;
import com.example.data.leave.LeaveBO;
import com.example.data.leave.LeaveVO;
import com.example.service.leave.LeaveService;
import com.example.service.leave.LeaveServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
public class LeaveController {
    private LeaveService leaveService;
    @Autowired
    public LeaveController(LeaveService leaveService){
        this.leaveService = leaveService;
    }
    //获取所有员工请假信息
    @GetMapping("/leave")
    public List<Leave> getAllLeaveInfo(){
        return leaveService.getAllLeaveInfo();
    }

    //获取某员工请假信息
    @GetMapping("/leave/id")
    public List<Leave> getLeaveInfoByEmpID(@RequestParam(value = "empID") long empID){
        return leaveService.getLeaveInfoByEmpID(empID);
    }

    // 添加员工请假申请
    @PostMapping("/leave")
    public List<Leave> addLeaveInfo(@RequestBody Leave leaveVO){
        return leaveService.addLeaveInfo(LeaveVO.convert(leaveVO));
    }

//    修改员工请假申请
    @PutMapping("/leave/id")
    public List<Leave> editLeaveInfo(@RequestBody Leave leaveVO) {
        return leaveService.editLeaveInfo(LeaveVO.convert(leaveVO));
    }

    //删除某员工请假申请
    @DeleteMapping("/leave/id")
    public void deleteLeaveInfo(@RequestParam(value = "appID") long appID,
                                                                                @RequestParam(value = "empID") long empID){
        leaveService.deleteLeaveInfo(appID,empID);
    }

}

